﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System.Diagnostics;
using Uipath_Web.Models;
using Uipath_Web.Tools;

namespace Uipath_Web.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;

        public HomeController(ILogger<HomeController> logger)
        {
            _logger = logger;
        }

        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }

        public string GetLicense() 
        {
            //在线获取License
            string url = "https://licensing01api.azurewebsites.net/api/Customer/RegisterCustomerAsync";
            Request_License request_License = new Request_License();
            request_License.Request_License_Default();
            string response_str;
            try
            {
                response_str = HttpHelper.PostUrlString(url, JsonConvert.SerializeObject(request_License));
            }
            catch (Exception ex)
            {
                response_str = ex.Message;
            }
            return response_str;
        }
    }
}